package app.productmanagement.web.Product.controller;

import app.productmanagement.Pojo.Result;
import app.productmanagement.web.Product.Pojo.dto.ProductRequest;
import app.productmanagement.web.Product.Service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/products")
@RequiredArgsConstructor
public class ProductController {

    private final ProductService productService;
    @PostMapping
    public Result<?> createProduct(@RequestBody ProductRequest productRequest) {
        // 创建新商品
        // TODO: 实现商品相关的接口逻辑

        return  productService.addProductAndTag(productRequest);
    }



    // 获取所有商品
    @GetMapping
    public Result<?> getAllProducts( @RequestParam( required = false, defaultValue = "1") int page,
                                     @RequestParam( required = false, defaultValue = "10") int limit) {
        return productService.getAllProducts(page,limit);
    }

    // 获取单个商品
    @GetMapping("/{id}")
    public Result<?> getProductById(@PathVariable int id) {

        return productService.getProduct(id);
    }



    // 更新商品信息
    @PutMapping("/{id}")
    public Result<?> updateProduct(@PathVariable int id, @RequestBody ProductRequest productRequest) {

        productService.updateProduct(id,productRequest);
        // TODO: 实现更新商品信息的逻辑
        return Result.success("更新商品信息");
    }

    // 删除商品
    @DeleteMapping("/{id}")
    public Result<?> deleteProduct(@PathVariable int id) {
        return productService.deleteProduct(id);
    }


}